Skip to content

fix(evm): make uint256 predicates and ABI-less event decoding work - #5

Draft
devblac wants to merge 2 commits into
mainfrom
fix/evm-predicates
Draft

devblac wants to merge 2 commits into
mainfrom
fix/evm-predicates

Conversation

@devblac

@devblac devblac commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Why

The README quickstart rule (USDC Transfer, value >= 1_000_000 * 1e6, no abi_dirs) could never fire, for two independent reasons:

  1. Predicates dropped *big.Int values. The EVM decoder yields *big.Int for uint256, but toNumber had no case for it and returned "not a number", so every numeric predicate on an EVM amount evaluated to false. Existing tests only used int, so this went unnoticed.
  2. ABI-less decoding broke on indexed args. Without an ABI, the synthetic event treated every argument as non-indexed and unnamed. For an ERC-20 Transfer (from/to in topics, only value in data) unpacking failed, and even on success there was no value key.

What changed

internal/engine/predicate.go

  • Numeric comparisons use big.Rat: exact for the full uint256/int256 range (float64 treated 1e24 + 1 == 1e24).
  • Accepts *big.Int and all sized int/uint types.
  • Only decimal literals are numeric, so to != 0x000… stays a string comparison.
  • Strips surrounding quotes on the right-hand side (sender == "0x…" used to compare against the quotes too) and compares 0x strings case-insensitively (checksummed vs lowercase), including in lists.

internal/source/evm/matcher.go

  • With no ABI, indexed arguments are inferred per log from the topic count (first N args), which also tells ERC-20 and ERC-721 Transfer apart.
  • Well-known events get named args (from/to/value, tokenId, Approval, ApprovalForAll, ERC-1155 TransferSingle); anything else gets arg0, arg1, ….
  • Event signatures are canonicalised (whitespace removed) before hashing topic0.
  • An invalid signature now fails at startup instead of silently never matching.

Also included: ci: install syft via install script — a pending release.yml change that was in the working tree, kept as its own commit. It runs syft's install script from main via curl | sh (not version-pinned); drop the commit if you'd rather not ship it here.

Reviewer notes

  • Heuristic limit: an ABI-less event whose indexed arguments are not the leading ones will get mismatched names; such events still need abi_dirs.
  • Behaviour change: rules with a malformed event signature now error on start.
  • README (UTF-16) not updated to document the ABI-less arg names.

Testing

  • New internal/engine/predicate_bigint_test.go (big ints, precision, addresses, plus an end-to-end test of the README rule through matcher + predicates) and internal/source/evm/matcher_synthetic_test.go.
  • All 8 new tests fail against main and pass here.
  • go vet ./... and go test ./... pass. Not exercised against a live RPC.

🤖 Generated with Claude Code

devblac and others added 2 commits November 24, 2026 00:05
Predicates silently rejected *big.Int values, so any rule on a
uint256 amount (e.g. "value >= 1_000_000 * 1e6") never fired.
Numeric comparisons now use big.Rat and are exact; quoted and
mixed-case hex addresses compare correctly.

Without abi_dirs, the synthetic event treated every argument as
non-indexed and unnamed, so ERC-20 Transfer logs failed to decode.
Indexed arguments are now inferred from the log's topic count, and
well-known events (ERC-20/721/1155) get named args; others use argN.
Whitespace in event signatures no longer changes topic0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant